<?php

class Mithos_CastleSiege {

    public function owner() {
        $result = $this->info();
        if (!empty($result) || !empty($result['guild'])) {
            return new Mithos_Guild($result['guild']);
        }
        return $result;
    }

    public function info() {
        $result = Mithos_Mssql::getInstance()->fetch('SELECT 
            MAP_SVR_GROUP AS server_group,
            SIEGE_START_DATE AS siege_start,
            SIEGE_END_DATE AS siege_end,
            SIEGE_ENDED AS ended,
            CASTLE_OCCUPY as occupy,
            OWNER_GUILD as guild,
            MONEY as money,
            TAX_RATE_CHAOS AS rate_chaos,
            TAX_RATE_STORE AS rate_store,
            TAX_HUNT_ZONE AS hunt_zone
            FROM MuCastle_Data
        ');
        if (!empty($result)) {
            $result['guild'] = new Mithos_Guild($result['guild']);
        }
        return $result;
    }

    public function connecteds($top = '*') {
        $top = $top !== '*' ? ' TOP ' . $top : '';
        $results = Mithos_Mssql::getInstance()->fetchAll('SELECT' . $top . ' 
            REG_SIEGE_GUILD AS guild,
            REG_MARKS as marks
            FROM MuCastle_REG_SIEGE
            ORDER BY REG_MARKS DESC, REG_SIEGE_GUILD
        ');
        return $results;
    }

}